package com.lanou3g.farmdoctor.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.AbsoluteSizeSpan;
import android.view.KeyEvent;
import android.view.View;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.Toast;

import com.lanou3g.farmdoctor.R;
import com.lanou3g.farmdoctor.application.FDApplication;
import com.lanou3g.farmdoctor.base.BaseActivity;

/**
 * 本类由: Risky 创建于: 15/11/24.
 */
public class QuickQuestionAty extends BaseActivity implements View.OnClickListener {

    private TextView cancelTv, submitTv;
    private ImageView imageView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_quickquestionaty);

        initView();
    }

    private void initView() {

        cancelTv = (TextView) findViewById(R.id.quick_cancel);
        submitTv = (TextView) findViewById(R.id.quick_submit);
        imageView = (ImageView) findViewById(R.id.quick_question_iv);

        cancelTv.setOnClickListener(this);
        submitTv.setOnClickListener(this);
        imageView.setOnClickListener(this);

        setMyHintSize(R.id.quick_et_first, "请简单输入您遇到的问题");
        setMyHintSize(R.id.quick_et_second, "请详细描述您遇到的问题，方便专家解答(选填)");
        setMyHintSize(R.id.quick_et_third, "添加与提问相关的作物名称(选填)");
    }

    /**
     * 设置EditText的hint字体大小
     */
    private void setMyHintSize(int etID, String msg) {
        EditText et = (EditText) findViewById(etID);
        SpannableString ss = new SpannableString(msg);
        AbsoluteSizeSpan ass = new AbsoluteSizeSpan(12, true);
        ss.setSpan(ass, 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        et.setHint(new SpannableString(ss));
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.quick_cancel:
                setMyTabHost();
                finish();
                break;
            case R.id.quick_submit:
                Toast.makeText(this, "功能未开启！", Toast.LENGTH_SHORT).show();
                break;
            case R.id.quick_question_iv:
                Toast.makeText(this, "功能未开启！", Toast.LENGTH_SHORT).show();
                break;
        }
    }

    /**
     * 返回时 设置tabHost标签
     */
    private void setMyTabHost() {
        TabHost tabHost = FDApplication.getMainActivity().getTabHost();
        tabHost.setCurrentTab(0);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            setMyTabHost();
            finish();
        }
        return false;
    }
}
